/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.statementView;
/**
 * 报表管理主窗体
 */
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.commons.util.SwingUtil;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.view.base.BaseInternalFrame;

public class StatementInternalFrame extends BaseInternalFrame {
	
	private static final long serialVersionUID = 1L;

	private JToolBar toolBar;//工具栏
	
	private JPanel main;//主面板
	private CardLayout main_layout;//主面板布局
	
	private JButton statementBuyButton;//采购报表按钮
	private StatementBuyPanel statementBuyPanel;//采购报表面板
	
	private JButton statementStockButton;//库存报表按钮
	private StatementStockPanel statementStockPanel;//库存报表面板
	
	private JButton statementSalesButton;//销售报表按钮
	private StatementSalesPanel statementSalesPanel;//销售报表面板

	private JButton statmentMoneyButton;//资金报表按钮
	private StatementMoneyPanel statmentMoneyPanel;//资金报表面板
	
	private JButton statmentProfitButton;//利润报表按钮
	private StatementProfitPanel statementProfitPanel;//利润报表面板
	
	public StatementInternalFrame(String title, boolean resizable,
			boolean closable, boolean maximizable, boolean iconifiable) {
		super(title, resizable, closable, maximizable, iconifiable);
		init();
	}
	private void init(){
		this.setLayout(new BorderLayout());
		this.initComponents();
		this.initListener();
	}
	//初始化组件
	private void initComponents() {
		toolBar = new JToolBar();
		toolBar.setFloatable(false);//设置工具栏不可移动
		statementBuyButton = new JButton("采购报表",SwingUtil.getOpenSwingImage("statements_purchase.png"));
		statementStockButton = new JButton("库存报表",SwingUtil.getOpenSwingImage("statements_stock.png"));
		statementSalesButton = new JButton("销售报表",SwingUtil.getOpenSwingImage("statements_sell.png"));
		statmentMoneyButton = new JButton("资金报表",SwingUtil.getOpenSwingImage("statements_funds.png"));
		statmentProfitButton = new JButton("利润报表",SwingUtil.getOpenSwingImage("statements_profit.png"));
		
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL71)){
			toolBar.add(statementBuyButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL72)){
			toolBar.add(statementStockButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL73)){
			toolBar.add(statementSalesButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL74)){
			toolBar.add(statmentMoneyButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL75)){
			toolBar.add(statmentProfitButton);
		}
//		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL77)){
//			toolBar.add(moneyInOntButton);
//		}
		
		toolBar.addSeparator();
		
		main_layout = new CardLayout();
		main = new JPanel(main_layout);
		
		this.add(toolBar, BorderLayout.NORTH);
		this.add(main, BorderLayout.CENTER);
	}
	
	//初始化监听器
	private void initListener() {
		statementBuyButton.addActionListener(this);
		statementStockButton.addActionListener(this);
		statementSalesButton.addActionListener(this);
//		statmentCommodityButton.addActionListener(this);
		statmentMoneyButton.addActionListener(this);
		statmentProfitButton.addActionListener(this);
//		moneyInOntButton.addActionListener(this);
	}
	
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == statementBuyButton) {
			//采购报表
			statementBuyPanel = new StatementBuyPanel();
			main.add(statementBuyPanel, "statementBuyPanel");
			main_layout.show(main, "statementBuyPanel");
			this.setTitle("报表管理--采购报表");
			Util.setButtonStatus(toolBar,statementBuyButton);
			//SwingUtilities.invokeLater(statementBuyPanel);
		} else if(e.getSource() == statementSalesButton) {
			//销售报表
			statementSalesPanel = new StatementSalesPanel();
			main.add(statementSalesPanel, "statementSalesPanel");
			main_layout.show(main, "statementSalesPanel");
			this.setTitle("报表管理--销售报表");
			Util.setButtonStatus(toolBar,statementSalesButton);
			//SwingUtilities.invokeLater(statementStockPanel);
		}else if(e.getSource() == statementStockButton) {
			//库存报表
			statementStockPanel = new StatementStockPanel();
			main.add(statementStockPanel, "statementStockPanel");
			main_layout.show(main, "statementStockPanel");
			this.setTitle("报表管理--库存报表");
			Util.setButtonStatus(toolBar,statementStockButton);
			//SwingUtilities.invokeLater(statementStockPanel);
		}  else if(e.getSource() == statmentMoneyButton) {
			//资金报表
			statmentMoneyPanel = new StatementMoneyPanel();
			main.add(statmentMoneyPanel, "statmentMoneyPanel");
			main_layout.show(main, "statmentMoneyPanel");
			this.setTitle("报表管理--资金报表");
			Util.setButtonStatus(toolBar,statmentMoneyButton);
			//SwingUtilities.invokeLater(statementStockPanel);
		} else if(e.getSource() == statmentProfitButton) {
			//利润报表
			statementProfitPanel = new StatementProfitPanel();
			main.add(statementProfitPanel, "statementProfitPanel");
			main_layout.show(main, "statementProfitPanel");
			this.setTitle("报表管理--利润报表");
			Util.setButtonStatus(toolBar,statmentProfitButton);
			//SwingUtilities.invokeLater(statementStockPanel);
		}
		main.updateUI();
	}
	public void showButton(){
		if (toolBar != null && toolBar.getComponentCount() != 0)
			((JButton)toolBar.getComponent(0)).doClick();
	}
	
	public void showButton(int type){
		switch(type){
			case 1:{statementBuyButton.doClick();break;}
			case 2:{statementSalesButton.doClick();break;}
			case 3:{statmentMoneyButton.doClick();break;}
			case 4:{statementStockButton.doClick();break;}
			case 5:{statmentProfitButton.doClick();break;}
		}
	}
}
